webpackJsonp([0],{

/***/ 0:
/***/ function(module, exports, __webpack_require__) {

	/* WEBPACK VAR INJECTION */(function(global) {module.exports = global["Index"] = __webpack_require__(1);
	/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ },

/***/ 1:
/***/ function(module, exports, __webpack_require__) {

	var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require, exports, module) {
		__webpack_require__(2);	
		__webpack_require__(3);
		__webpack_require__(4);
		
		var moduleMap=__webpack_require__(5);
		
		var SidebarMenu=__webpack_require__(28);
		
		var Index=function(config){
			this.config=$.extend({},Index.DEFAULT,config);
			this.$div=$('#main-container');
			
			this.init();
		};
		
		Index.prototype={
			init:function(){
				var that=this;
				//0.导航栏渲染
				
				//1.菜单渲染
				var menuDeferred = $.Deferred()
				this.sidebarMenu=new SidebarMenu(this.$div,$.extend(this.config,{
					afterInit:function(){
						menuDeferred.resolve();
					}
				}));
				
				this.pageStack=[];//用来保存工作区页面层次深度{page模块,config}
				$.when(menuDeferred).done(function(){
					//2.面包屑
					that.initBreadCrumb();
					
					//3.工作区，页面切换效果:增加一个内嵌iframe
					that.curPage={};//当前页的组件对象
					that.$workspace=$('#workspace');
					
					//4.路由设置
					that.initRouter();
				});
			},
			toParentPage:function(){
				if(this.pageStack.length==0)
					return;
				
				var href=window.location.href;
				href=href.substring(0,href.lastIndexOf('/'));
				var menuId=href.substring(href.indexOf('#!'),href.length);
				menuId=menuId.substr(2);
				if(menuId.indexOf('/')==0)
					menuId=menuId.substr(1);
				if(this.sidebarMenu.menuItem[menuId])
				{
					window.location.href=href;
					return;
				}	
				
				//面包屑反应
				this.breadCrumbVM.data.pop();
				//地址改动
				window.location.href=href;
				//工作区反应
				this.curPage&&this.curPage.destroy&&this.curPage.destroy();
				var pageStackItem=this.pageStack.pop(),Page=pageStackItem.page;
				this.curPage=new Page(this.$workspace,$.extend({},this.config,pageStackItem.config),undefined,this);
			},
			toSubPage:function(module,config,moduleName){
				if(module==undefined)
					return;
				
				this.pageStack.push({
					page:this.curPageModule,
					config:this.curPage.config
				});
				
				//面包屑反应
				this.breadCrumbVM.data.push({
					href:'',
					name:moduleName,
					className:'',
					id:'',
					pid:''
				});
				//地址改动
				window.location.href=window.location.href+'/'+moduleName;
				
				//工作区反应
				this.curPage&&this.curPage.destroy&&this.curPage.destroy();
				var Page=module;
				this.curPageModule=Page;
				this.curPage=new Page(this.$workspace,$.extend({},this.config,config),undefined,this);
			},
			directPage:function(menuId,path,params){//工作区页面跳转
				var that=this;
				
				//菜单反应
				var menuPaths=this.sidebarMenu.selectMenuItem(menuId);
				
				//面包屑反应，设置this.breadCrumbVM.data
				this.breadCrumbVM.data.splice(0,this.breadCrumbVM.data.length);
				menuPaths&&$.map(menuPaths,function(menu){that.breadCrumbVM.data.unshift(menu)});
				
				//重置页面栈
				this.pageStack=[];
				
				//工作区反应
				this.curPage&&that.curPage.destroy&&that.curPage.destroy();
				var Page=moduleMap[menuId];
				this.curPageModule=Page;
				Page&&(this.curPage=new Page(this.$workspace,$.extend({},this.config,{
					menuId:menuId,
					path:path,
					params:params
				}),undefined,this));
			},
			initRouter:function(){//4.路由设置
				var that=this;
				//添加路由规则
				$.map(this.sidebarMenu.getHashs(),function(hash){
					avalon.router.add("/"+hash.replace(/\?.*/i,''), function () {
						that.directPage(this.path.substr(1),this.path,this.query);
					});
				});
				//启动路由监听
				avalon.history.start({
				    root: "/"
				});
			},
			initBreadCrumb:function(){
				var that=this;
				this.$breadcrumb=$('#breadcrumb');
				this.breadCrumbVM= avalon.define({
	                $id: "breadcrumb",
	                hasHref:function(index,el){
	                	return (index!=that.breadCrumbVM.data.length-1)&&el.href!='#';
	                },
	                data:[]
	            });
				avalon.scan(this.$breadcrumb.get(0),this.breadCrumbVM);
			}
		};	
		
		Index.DEFAULT={
				
		};
		
		return  Index;
	}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));

/***/ },

/***/ 28:
/***/ function(module, exports, __webpack_require__) {

	var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require, exports, module) {
		
		__webpack_require__(2);
		/**参考https://segmentfault.com/a/1190000006192449*/
		var menuItemTpl='<ul class="submenu"><li ms-for="(index,el) in @tree">'+
				' <a ms-attr="{href:el.href,id:el.id}" ms-class="@parentItemClass(el)" >'+
	       			'<i ms-class="el.className"></i>'+
	       			'<span ms-class="{\'menu-text\':@level.index==0}" ms-text="el.name"></span>'+
	       			'<b ms-if="el.children" class="arrow icon-angle-down"></b>'+
	       		'</a><div ms-if="el.children" ms-html="@renderSubMenu(el)"></div></li></ul>';
		/*data:[{id:'',href:'', className:'',name:'',pid:'',children:[]}] 
		 *  #!id和href.hash相等，除非是# , href的hash用来关联获取那个js页面  */
		avalon.component('ms-menu-tree',{
		    template:menuItemTpl,
		    defaults: {
		       tree:[],
		       level:{index:0},
		       parentItemClass:function(item){
		    	   return item.children?'dropdown-toggle':'';
		       },
		       renderSubMenu:function(item){
		    	   return item.children&&item.children.length ? ('<wbr ms-widget="{is:"ms-menu-tree", $id:"tree_'+item.id+'",tree:el.children,level:{index:@level.index+1}}" />') : '';
			   }
		    }
		})
		
		
		var SidebarMenu=function($container,config,data){
			this.getUrl=Common.getUrl.bind(this);
			this.config=$.extend({},SidebarMenu.DEFAULT,config);
			this.data=data;
			this.$container=$container;
			this.$div=$('#sidebar');
				
			if(this.data)
			{
				this.init();
				return;
			}
			
			var that=this;
			$.ajax(this.getUrl('sidebarMenu'),{
				type:'POST',
				dataType:'json'
			}).done(function(data){
				that.data=data;
				that.init();
			}).fail(function(data){
				that.data=[];
				that.init();
			});
					
		};
		
		SidebarMenu.prototype={
			init:function(){
				this.vm = avalon.define({
	                $id: "sidebar",
	                config:this.config,
	                curMenuId:'',
	                data:this.data
	            });
				avalon.scan(this.$div.get(0),this.vm);
				this.render();
				this.initMenuMap();
				this.config.afterInit&&this.config.afterInit();
			},
			initMenuMap:function(){//构造菜单id映射
				//<id,menuItem>
				this.menuItem={};
				var menuItem=this.menuItem;
				var menuMapFn=function(tree,pItem){
					$.map(tree,function(item){
						menuItem[item.id]=item;
						pItem&&(item.pid=pItem.id);
						if(item.children&&item.children.length>0)
							menuMapFn(item.children,item);
					});
				};
				menuMapFn(this.data);
			},
			render:function(){
				$('ul[wid=tree_]',this.$div).removeClass("submenu").addClass("nav nav-list");
				ace.handle_side_menu(jQuery);
				try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
			},
			getCurrentMenuId:function(){
				return this.vm.curMenuId;
			},
			selectMenuItem:function(itemId){
				if(itemId=='#')
					return;
				this.$div.find('.active').removeClass('active');
				this.$div.find('.open').removeClass('open');
				//切换curMenuId
				this.vm.curMenuId=itemId;
				//设置actice,open,菜单路径上的父菜单
				var menuItem=this.menuItem[itemId],res=[];
				while(menuItem)
				{
					$('#'+menuItem.id,this.$div).parent().addClass('active');
					res.push(menuItem.$model);
					menuItem=this.menuItem[menuItem.pid];
					menuItem&&$('#'+menuItem.id,this.$div).parent().addClass('open');
				}
				this.menuPath=res;
				return res;
			},
			getHashs:function(){
				//返回菜单里所有的href
				var res=[];
				var getTreeHash=function(tree){
					$.map(tree,function(item){
						res.push(item.href.substr(2));
						if(item.children&&item.children.length>0)
							getTreeHash(item.children);
					});
				};
				getTreeHash(this.data);
				return res;
			},
			urls:{
				sidebarMenu:'/portal/sidebarMenu.jhtml'
			}	
		};	
		
		SidebarMenu.DEFAULT={
				
		};
		
		return  SidebarMenu;
	}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));

/***/ }

});